#ifndef __TRUECCID_H_
#define __TRUECCID_H_

#include <inttypes.h>

#ifdef __cplusplus
extern "C" {
#endif

// ============================ Prototypes =====================================
void SCR_Task(void);

void CCID_Init(void);

void callback_XfrBlock(uint8_t *AData, uint16_t ALen);
void callback_SlotStatus();
void notify_TimeExtension(uint8_t AExtentValue);
void notify_SlotChange(bool ACardIsIn);


// ============================== Types ========================================
typedef struct ccid_msg_header {
    uint8_t type;
    uint32_t length;
    uint8_t slot;
    uint8_t seq;
    union
    {
        uint8_t spec[3];
        struct
        {
            uint8_t status;
            uint8_t error;
            uint8_t spec0;
        };
    };
} ccid_msg_header_t;

// PC_to_RDR_Parameters
struct ccid_abProtocolDataStructureT0_t {
    uint8_t bmFindexDindex;
    uint8_t bmTCCKST0;
    uint8_t bGuardTimeT0;
    uint8_t bWaitingIntegerT0;
    uint8_t bClockStop;
};

struct ccid_abProtocolDataStructureT1_t {
    uint8_t bmFindexDindex;
    uint8_t bmTCCKST1;
    uint8_t bGuardTimeT1;
    uint8_t bmWaitingIntegersT1;
    uint8_t bClockStop;
    uint8_t bIFSC;
    uint8_t bNadValue;
};

// ============================ Defines ========================================
/* PC to READER messages */
#define PC_to_RDR_IccPowerOn    0x62
#define PC_to_RDR_IccPowerOff   0x63
#define PC_to_RDR_GetParameters 0x6C
#define PC_to_RDR_SetParameters 0x61
#define PC_to_RDR_GetSlotStatus 0x65
#define PC_to_RDR_XfrBlock      0x6F
#define PC_to_RDR_Escape        0x6B

/* READER to PC messages */
#define RDR_to_PC_DataBlock     0x80
#define RDR_to_PC_SlotStatus    0x81
#define RDR_to_PC_Parameters    0x82
#define RDR_to_PC_Escape        0x83

// Interrupt-IN messages
#define RDR_to_PC_NotifySlotChange  0x50
#define RDR_to_PC_HardwareError     0x51

/* READER error codes */
#define CMD_NOT_SUPPORTED   0x00
#define ICC_MUTE            0xFE

/* Control Endpoint Requests */
#define ABORT   0x01
#define GET_CLOCK_FREQUENCIES 0x02
#define GET_DATA_RATES 0x03

#ifdef __cplusplus
}
#endif

#endif
